﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Aden.Model.Stock;
using Aden.Model;
using Aden.DAL.StockData;
using Aden.Model.SOCommon;

namespace Aden.BLL.StockData
{
    public class StockDataHelper
    {
        private readonly static StockDataFactory StockDataFactory = new StockDataFactory();

        /// <summary>
        /// 采购入库和消耗的采购-日期列表
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public static List<DateSuppliers> SupplierDate(StockParam param)
        {
            try
            {
                List<DateSuppliers> SupplierDate = StockDataFactory.SupplierDate(param.costCenterCode,param.orderType);
                if (SupplierDate == null) throw new Exception("DAL.StockData. StockDataFactory.SupplierDate()==null");
                return SupplierDate;
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog(new Log()
                {
                    message = ex.Message
                }, "SupplierDate");
                return null;
            }
        }
        /// <summary>
        /// 库存管理类型：入库、出库、转仓、消耗
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public static List<OrderType> GetOrderType(OrderType param)
        {
            try
            {
                List<OrderType> GetOrderType = StockDataFactory.GetOrderType(param.orderName);
                if (GetOrderType == null) throw new Exception("DAL.StockData. StockDataFactory.GetOrderType()==null");
                return GetOrderType;
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog(new Log()
                {
                    message = ex.Message
                }, "GetOrderType");
                return null;
            }
        }
        /// <summary>
        /// 读取库存明细数据
        /// </summary>
        /// <param name="date"></param>
        /// <param name="costCenterCode"></param>
        /// <param name="supplierCode"></param>
        /// <param name="customerCode"></param>
        /// <param name="coa"></param>
        /// <param name="orderType"></param>
        /// <returns></returns>
        public static List<TransData> GetTransactionDataList(DateTime date, string costCenterCode,
            string supplierCode, string customerCode, string coa, OrderType orderType,string appType, string productDesc)
        {
            try
            {
                List<TransData> GetTransactionDataList = StockDataFactory.GetTransactionDataList(date,costCenterCode, 
                    supplierCode,customerCode,coa, orderType, appType, productDesc);
                //if (GetTransactionDataList == null) throw new Exception("DAL.StockData. StockDataFactory.GetOrderType()==null");
                return GetTransactionDataList;
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog(new Log()
                {
                    message = ex.Message
                }, "GetOrderType");
                return null;
            }
        }
        /// <summary>
        /// 上传库存数据
        /// </summary>
        /// <param name="date"></param>
        /// <param name="costCenterCode"></param>
        /// <param name="creator"></param>
        /// <param name="data"></param>
        /// <param name="orderType"></param>
        /// <returns></returns>
        public static int SaveToTransactionData(StockParam param)
        {
            try
            {
                int i = 0;
                if (param.orderType.guid == "259724C2-7979-45DC-BB40-19F12D50ABB9" || param.orderType.guid == "8FD9674B-3177-4F94-B826-F165448D370D")
                {
                    i = StockDataFactory.SaveToTransactionData(param.date, param.costCenterCode, param.creater, param.data, param.orderType, param.productDesc);
                }
                else if(param.orderType.guid == "86BF9D51-CFEB-4A28-8910-D698CFEBCA17")
                {
                    i = StockDataFactory.SaveDailyTicket(param.date, param.costCenterCode, param.creater, param.data, param.orderType);
                }
                return i;
            }
            catch(Exception ex)
            {
                LogHelper.WriteLog(new Log()
                {
                    message = ex.Message
                }, "SaveToTransactionData");
                return 0;
            } 
        }
        /// <summary>
        /// 库存消耗 - 早、中、晚餐下拉框选项
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public static List<productDescData> GetProductDescOptions(StockParam param)
        {
            try
            {
                List<productDescData> GetProductTypeOptions = StockDataFactory.GetProductDescOptions(param);
                return GetProductTypeOptions;
            }
            catch(Exception ex)
            {
                LogHelper.WriteLog(new Log()
                {
                    message = ex.Message
                }, "GetProductTypeOptions");
                return null;
            }
        }
    }
}
